const usingCtrlChannel = {
  state: {
    usingCtrlChannel: []
  },
  mutations: {
    setusingCtrlChannel (state, data) {
      state.usingCtrlChannel = data
    },
    pushUsingCtrlChannel (state, data) {
      let exist = state.usingCtrlChannel.find(item => item.ccu_tunnel_no === data.ccu_tunnel_no)
      if (exist) return
      state.usingCtrlChannel.push(data)
    },
    deleteUsingCtrlChannel (state, data) {
      for (let i in state.usingCtrlChannel) {
        if (state.usingCtrlChannel[i].ccu_tunnel_no === data.ccu_tunnel_no) {
          state.usingCtrlChannel.splice(i, 1)
        }
      }
    }
  },
  actions: {
    async getUsingCtrlChannel (context) {
      let response = await context.dispatch('axios', {
        method: 'get',
        url: '/api/abs/ncp/using_ctrl_channel/'
      })
      context.commit('setusingCtrlChannel', response.data)
    }
  },
  getters: {
    getCtrlFreqSegmentChartData: (state) => {
      let res = []
      for (let tunnelItem of state.usingCtrlChannel) {
        if (tunnelItem.type === 0) {
          res.push({
            satellite: tunnelItem.satellite_id,
            satellite_name: tunnelItem.satellite_name,
            type: 'ctrlTdm',
            down_freq_begin: tunnelItem.down_freq_begin / 1000,
            down_freq_end: tunnelItem.down_freq_end / 1000,
            power: tunnelItem.power,
            bandWidth: (tunnelItem.down_freq_end - tunnelItem.down_freq_begin) / 1000,
            centerFreq: (tunnelItem.down_freq_begin + tunnelItem.down_freq_end) / 2000,
            color: 'rgba(245, 166, 35, 1)'
          })
        } else if (tunnelItem.type === 1) {
          res.push({
            satellite: tunnelItem.satellite_id,
            satellite_name: tunnelItem.satellite_name,
            type: 'ctrlAloha',
            down_freq_begin: tunnelItem.down_freq_begin / 1000,
            down_freq_end: tunnelItem.down_freq_end / 1000,
            power: tunnelItem.power,
            bandWidth: (tunnelItem.down_freq_end - tunnelItem.down_freq_begin) / 1000,
            centerFreq: (tunnelItem.down_freq_begin + tunnelItem.down_freq_end) / 2000,
            color: 'rgba(154, 50, 246, 1)'
          })
        } else if (tunnelItem.type === 2) {
          res.push({
            satellite: tunnelItem.satellite_id,
            satellite_name: tunnelItem.satellite_name,
            type: 'sharedBusinessSend',
            down_freq_begin: tunnelItem.down_freq_begin / 1000,
            down_freq_end: tunnelItem.down_freq_end / 1000,
            power: tunnelItem.power,
            bandWidth: (tunnelItem.down_freq_end - tunnelItem.down_freq_begin) / 1000,
            centerFreq: (tunnelItem.down_freq_begin + tunnelItem.down_freq_end) / 2000,
            color: 'rgba(245, 166, 35, 1)'
          })
        } else if (tunnelItem.type === 3) {
          res.push({
            satellite: tunnelItem.satellite_id,
            satellite_name: tunnelItem.satellite_name,
            type: 'sharedBusinessRecv',
            down_freq_begin: tunnelItem.down_freq_begin / 1000,
            down_freq_end: tunnelItem.down_freq_end / 1000,
            power: tunnelItem.power,
            bandWidth: (tunnelItem.down_freq_end - tunnelItem.down_freq_begin) / 1000,
            centerFreq: (tunnelItem.down_freq_begin + tunnelItem.down_freq_end) / 2000,
            color: 'rgba(154, 50, 246, 1)'
          })
        }
      }
      return res
    }
    // getCtrlFreqSegmentChartData: (state) => {
    //   let res = []
    //   state.usingCtrlChannel.forEach(item => {
    //     for (let tunnelItem of item.tunnels) {
    //       if (tunnelItem.type === 0) {
    //         res.push({
    //           type: 'ctrlTdm',
    //           businessCuDevice: [item.caller_cu, item.called_cu],
    //           workFreq: tunnelItem.power,
    //           bandWidth: (tunnelItem.upFreqEnd - tunnelItem.upFreqBegin) / 1000,
    //           centerFreq: (tunnelItem.upFreqBegin + tunnelItem.upFreqEnd) / 2000,
    //           user: 'com-wave',
    //           fillStyle: 'rgba(107,175,229,0.4)',
    //           strokeStyle: 'rgba(78,109,157,1)'
    //         })
    //       } else if (tunnelItem.type === 1) {
    //         res.push({
    //           type: 'ctrlAloha',
    //           businessCuDevice: [item.caller_cu, item.called_cu],
    //           workFreq: tunnelItem.power,
    //           bandWidth: (tunnelItem.upFreqEnd - tunnelItem.upFreqBegin) / 1000,
    //           centerFreq: (tunnelItem.upFreqBegin + tunnelItem.upFreqEnd) / 2000,
    //           user: 'com-wave',
    //           fillStyle: 'rgba(220,213,209,0.4)',
    //           strokeStyle: 'rgba(222,146,102,1)'
    //         })
    //       }
    //     }
    //   })
    //   return res
    // }
  }
}
export default usingCtrlChannel
